<template>
  <div>
    <el-row style="width: 100%; display: block; float: left; margin-top: 30px;margin-bottom: 30px;">
    </el-row>
    <el-row>
      <el-col :span="18">
        <div class="grid-content bg-purple">
          <el-card class="box-card" style="width: 99%;">
            <div slot="header" class="clearfix">
              <el-descriptions class="margin-top" title="个人信息" 
              style="color: #67C23A;font-weight: bolder;"
              :column="3" border>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-picture"></i>
                    头像
                  </template>
                  <el-avatar :size="large" :src="myInfo.icon" v-if="myInfo.icon"></el-avatar>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-user"></i>
                    用户名
                  </template>
                  {{ myInfo.username }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-mobile-phone"></i>
                    手机号
                  </template>
                  {{ myInfo.linkTel }}
                </el-descriptions-item>
                <el-descriptions-item contentClassName>
                  <template slot="label">
                    <i class="el-icon-location-outline"></i>
                    省份
                  </template>
                  {{ address }}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-tickets"></i>
                    身份
                  </template>
                  <el-tag size="small" type="warning" v-if="myInfo.userType==0">超级管理员</el-tag>
                  <el-tag size="small" type="" v-if="myInfo.userType==1">管理员</el-tag>
                  <el-tag size="small" type="success" v-if="myInfo.userType==2">普通用户</el-tag>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-message"></i>
                    个人邮箱
                  </template>
                  {{myInfo.email}}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-s-custom"></i>
                    真实姓名
                  </template>
                  {{myInfo.name}}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-bank-card"></i>
                    实名
                  </template>
                  <el-tag size="small" type="primary" v-if="myInfo.icCode">已实名</el-tag>
                  <el-tag size="small" type="danger" v-if="!myInfo.icCode&&!myInfo">未实名</el-tag>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-lock"></i>
                    身份证号码
                  </template>
                  <el-input  v-model="myInfo.icCode" show-password></el-input>
                </el-descriptions-item>
              </el-descriptions>
              <br /><br />
              <el-button size="medium" type="primary" @click="toOrderDetail()">返回</el-button>
              <el-button size="medium" type="warning" @click="uodateInfo(myInfo.id)">修改</el-button>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import newAxios from "../../utils/axios";
export default {
  data() {
    return {
      myInfo: {},
      addressList: [],
      address:''
    };
  },
  created() {
    this.getUser();
    this.findProvinceByid();
    this.$router.afterEach((to, from) => {
       if (to.path == '/myInfo') {
      //    // 调用刷新方法
         location.reload();
       }
     });
  },
  mounted() {
    this.getUser();
    this.findProvinceByid();
  },
  methods: {
    toOrderDetail() {
      this.$router.back();
    },
    uodateInfo(id) {
      //  this.$router.replace("/updateMaterial");
      this.$router.push({
        path: "/updateMaterial",
        query: {
          userId: id,
        },
      });
    },
    getUser() {
      newAxios
        .get("/admin/findUserById")
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            console.log(res.data);
            this.myInfo = res.data;
          }else{
            this.$message.error("请先登录噢亲！！");
          }
        })
        .catch((err) => {
         console.log(err);
        });
    },
    findProvinceByid() {
      newAxios
        .get("/admin/findProvinceByid")
        .then((res) => {
          console.log(res.data.data);
          this.addressList = res.data.data;
          for (let i = 0; i < this.addressList.length; i++) {
            if(this.myInfo.province==i+1){
               this.address = this.addressList[i].key;
               console.log("地址："+this.address);
            }
          }
        })
        .catch((err) => {
         console.log(err);
        });
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
